//package com.dk.academic.common;
//
//import org.aspectj.lang.annotation.*;
//import org.elasticsearch.client.transport.TransportClient;
//import org.elasticsearch.common.settings.Settings;
//import org.elasticsearch.common.transport.InetSocketTransportAddress;
//import org.elasticsearch.transport.client.PreBuiltTransportClient;
//import org.springframework.stereotype.Component;
//
//import java.net.InetAddress;
//import java.net.UnknownHostException;
//
//import static com.dk.academic.common.Common.HOST;
//import static com.dk.academic.common.Common.PORT;
//
///**
// * @Author: 廉雪峰
// * @Date: 2018/10/25 16:28
// * @Version 1.0
// *
// * 针对Search的切面，每次查询打开，结束关闭连接
// */
//
//@Aspect
//@Component
//public class SearchAspect {
//
//
//    @Pointcut("execution(public * com.dk.academic.controller.SearchController.*(..))")
//    public void WebPoint() {
//
//    }
//
//    @Before("WebPoint()")
//    public void doBefore() throws UnknownHostException {
//        System.out.println("执行搜索前获得连接");
//        //创建客户端
//        // PreBuiltTransportClient 需要版本5.+，大概是6版本以上setting不能为空 需要制定type
//       Common.client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddresses(
//                new InetSocketTransportAddress(InetAddress.getByName(HOST),PORT));
//
//        System.out.println("Elasticsearch connect info:" + Common.client.toString());
//    }
//
//    @AfterThrowing("WebPoint()")
//    public void afterThrowing() {
//        System.out.println("发生异常");
//    }
//
//    @After("WebPoint()")
//    public void doAfter() {
//        if (Common.client != null) {
//            Common.client.close();
//            System.out.println("连接正在关闭");
//        }
//        return;
//    }
//}
